'''
Created on Jul 19, 2010

@author: riche
'''

from ft.framework import component

class GenericQuorum(component.Implementation):
    '''
    classdocs
    '''


    def __init__(self, name, threshold):
        '''
        Constructor
        '''
        component.Implementation.__init__(self, name)
        self.__threshold__ = threshold
        self.__msgs__ = {}
        
    def process_msg(self, msg):
        body = msg
        if(body not in self.__msgs__):
            self.__msgs__[body] = 1
        else:
            self.__msgs__[body] += 1
        
        if(self.__msgs__[body] == self.__threshold__):
            print('found quorum: ' + str(body))
            self.send_out('q_found', body)
        if(self.__msgs__[body] > self.__threshold__):
            pass
